import {$post,$setToken} from '../utils/request'
import md5 from 'js-md5'
import {message} from 'ant-design-vue'

export const $login = async (params)=>{
    params.password =  md5(md5(params.password).split('').reverse().join(''))
    let data = await $post('login',params)
    console.log(data);
    let {success,msg} = data
    if(success){
        let{token,data:userdata} = data
        console.log(token);
        //token 存缓存
        sessionStorage.setItem('token',token)
        //更新请求头token
        $setToken(token)
        let user ={
            username:userdata.username,
            role:userdata.role
        }
        sessionStorage.setItem("user",JSON.stringify(user))
        message.success(msg)
    }else{
        message.error(msg)
    }
    return success
}